#include <arpa/inet.h>
#include <sys/socket.h>
#include <netdb.h>
#include <ifaddrs.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <netinet/in.h>
#include <math.h>
#include <linux/kernel.h>

#define INT32 int
//#define DIAGDL_RESULT_FILE "/tmp/.diagdl_result.txt"
#define DIAGDL_RESULT_FILE "./diagdl_result.txt"
#define DIAGDL_FILE "/tmp/diagdl_file"

#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif

void sysinfo_dump(struct sysinfo *info)
{
	printf("totalram=%lu\n", info->totalram);
	printf("freeram=%lu\n", info->freeram);
	printf("sharedram=%lu\n", info->sharedram);
	printf("bufferram=%lu\n", info->bufferram);
	printf("totalswap=%lu\n", info->totalswap);
	printf("freeswap=%lu\n", info->freeswap);
	printf("procs=%u\n", info->procs);
}

void selftest_diagnostics_start()
{
	struct sysinfo info;

	memset(&info, 0, sizeof(struct sysinfo));
	sysinfo(&info);
	sysinfo_dump(&info);
}

INT32 selftest_diagnostic_get_results(char *value)
{   
	struct sysinfo info;

	memset(&info, 0, sizeof(struct sysinfo));
	sysinfo(&info);
	//sysinfo_dump(&info);
	sprintf(value, "totalram=[%lu], freeram=[%lu], sharedram=[%lu], bufferram=[%lu], totalswap=[%lu], freeswap=[%lu]",
				info.totalram, info.freeram, info.sharedram, info.bufferram, info.totalswap, info.freeswap);

	return 0;
}

void selftest_diagnostics_print()
{
	char value[256]={0};
	
}


int main(int argc, char *argv[])
{
	int index;
	char result[1024] = {0};
	
	//selftest_diagnostics_start();
	selftest_diagnostic_get_results(result);
	printf("result = [%s]\n", result);
	//selftest_diagnostics_print();

    return 0;
}
